<template>
  <j-modal :title="title" :width="600" :visible="visible" :maskClosable="false" @close="close" cancelText="关闭">
    <div style="margin: 0 auto">
      <a-form-model ref="form" :label-col="labelCol" :wrapper-col="wrapperCol">
        <a-form-model-item label="模型名称">
          <a-input v-model="model.modelName"></a-input>
        </a-form-model-item>
        <a-form-model-item label="模型表名">
          <a-input v-model="model.modelTableName"></a-input>
        </a-form-model-item>
        <a-form-model-item label="业务类型">
          <a-select v-model="model.modelType">
            <a-select-option v-for="(item, index) in typeList" :key="index" :value="item.value">
              {{ item.label }}
            </a-select-option>
          </a-select>
        </a-form-model-item>
      </a-form-model>
    </div>
    <!-- table区域-end -->
  </j-modal>
</template>
<script>
import { httpAction, getAction } from '@/api/manage'

export default {
  name: 'addTreeNode',
  props: ['rightClickSelectedNode'],
  components: {},
  data() {
    return {
      isAdd: true,
      labelCol: { span: 4 },
      wrapperCol: { span: 18 },
      title: '元数据模型增加',
      visible: false,
      model: {},
      typeList: [
        {
          value: 0,
          label: '主数据',
        },
        {
          value: 1,
          label: '业务数据',
        },
      ],
      url: {
        add: '/metaDataModel/addMetaDataModel',
        edit: '/metaDataModel/updateMetaDataModel',
      },
    }
  },
  created() {},
  methods: {
    add(record) {
      console.log(record, 'record----')
      // if (typeof record == 'string') {
      //   this.model = {
      //     pid: '0',
      //     modelTableName: '',
      //     proid: record,
      //   }
      // } else {
      //   this.model = {
      //     parentName: record.itemName,
      //     pid: record.id,
      //     proid: record.proId,
      //     itemname: '',
      //   }
      // }
      this.isAdd = true
      this.visible = true
    },
    edit(record) {
      this.title = '元数据模型编辑'
      this.model = JSON.parse(JSON.stringify(record))
      this.isAdd = false
      this.visible = true
    },
    close(isSubmit) {
      if (isSubmit) {
        this.saveData()
      } else {
        this.visible = false
      }
    },
    saveData() {
      let url, type
      if (!this.model.id) {
        url = this.url.add
        type = 'post'
      } else {
        url = this.url.edit
        type = 'put'
      }
      httpAction(url, { ...this.model }, 'post').then((res) => {
        if (res.success) {
          this.$message.success(res.message)
          this.$emit('ok',this.model)
          this.visible = false
        } else {
          this.$message.error(res.message)
        }
      })
    },
  },
}
</script>

<style lang="less" scoped>
.name-type {
  width: 110px;
  margin-left: 5px;
  border: 1px solid #e0e0e0;

  /deep/ .ant-select-selection {
    box-sizing: border-box;
    min-height: 27px !important;

    .ant-select-selection__rendered {
      line-height: 27px !important;
    }
  }
}
</style>
